/* Exercise of TC++PL in chapter 5
   11. Read a sequence of words from input.Use Quit as a word that terminates
   the input. Print the words in the order they were entered. Don't print
   a word twice. Modify the program to sort the words before printing them.
*/
#include <iostream>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <list>
#include <utility>

using std::cout;
using std::endl;

using std::cin;
using std::set;
using std::string;
using std::list;
using std::pair;
using std::ostream_iterator;


int main()
{
    typedef set<string> WordSet;
    typedef WordSet::iterator WordIter;
    typedef list<string> Index;

    WordSet ws;
    Index index;
    
    for(string word;cin >>word , word != "Quit";)
    {
        pair<WordIter,bool> pa = ws.insert(word);
        if(pa.second)
            index.push_back(*pa.first);
    }
    std::copy(index.begin(),index.end(),ostream_iterator<string>(cout,"    "));
    cout << endl;
    //std::copy(index.begin(),index.end(),ostream_iterator<WordIter>(cout,"\n"));
    std::copy(ws.begin(),ws.end(),ostream_iterator<string>(cout,"     "));
}


        
